import MUtil from 'util/MUtil.jsx';
const mUtil = new MUtil();

class UserService {

  validateInput(loginInfo) {
    if (typeof loginInfo.username !== 'string'
      || loginInfo.username.replace(/^\s+|\s+$/gm, '').length === 0) {
      return {
        status: false,
        msg: '用户名不能为空'
      }
    }
    if (typeof loginInfo.password !== 'string'
      || loginInfo.password.replace(/^\s+|\s+$/gm, '').length === 0) {
      return {
        status: false,
        msg: '密码不能为空'
      }
    }
    return {
      status: true,
      msg: '验证通过'
    };
  }

  login(loginInfo) {
    return mUtil.request({
      method: 'post',
      url: '/manage/user/login.do',
      data: loginInfo
    });
  }

  logout() {
    return mUtil.request({
      method: 'post',
      url: '/user/logout.do'
    });
  }

  getUserList(pageNum) {
    return mUtil.request({
      method: 'post',
      url: '/manage/user/list.do',
      data: { pageNum }
    });
  }

}

export default UserService;